<template>
  <!--车辆在场查询-->
  <div class="contentRight2">
    <div id="tools">

      <div class="height8"></div>
      <!-- 查询条件 -->
      <a-form layout="inline" style="text-align: left;padding: 0 10px;" :selfUpdate="true">
        <a-form-item label="关键字" class="marginBtm">
          <a-input v-model="queryValue" allowClear placeholder="请输入工号/姓名/车牌"
                   @pressEnter="inquireStart"/>
        </a-form-item>

        <a-form-item label="停车时长" class="marginBtm">
          <a-select default-value="不限" showSearch
            style="width: 100px;margin-right: 1px"
            @search="handleMenuSearch"
            @change="handleMenuChange"
            v-model="statusId"
          >
            <a-select-option v-for="item in approvalStatus" :key="item.id">
              {{item.name}}
            </a-select-option>
          </a-select>
            <a-select
              style="width: 70px"
              v-model="timeTypeId"
            >
            <a-select-option v-for="item in timeTypeList" :key="item.id">
              {{item.name}}
            </a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item label="车辆类型" class="marginBtm">
          <a-dropdown class="min-width-140">
            <a-menu slot="overlay" @click="carTypeClick">
              <a-menu-item :key="item.typeId" v-for="item in carTypeList">{{item.name}}</a-menu-item>
            </a-menu>
            <a-button>
              <div class="query-conditions">
                {{ carTypeName }}
                <a-icon type="down"/>
              </div>
            </a-button>
          </a-dropdown>
        </a-form-item>

        <a-form-item label="基地" class="marginBtm">
          <a-dropdown class="min-width-120">
            <a-menu slot="overlay" @click="baseClick">
              <a-menu-item :key="item.id" v-for="item in baseList">{{item.name}}</a-menu-item>
            </a-menu>
            <a-button>
              <div class="query-conditions">
                {{ baseName }}
                <a-icon type="down"/>
              </div>
            </a-button>
          </a-dropdown>
        </a-form-item>
        <a-form-item label="区域" class="marginBtm">
          <a-dropdown class="min-width-140">
            <a-menu slot="overlay" @click="areaMenuClick">
              <a-menu-item :key="item.id" v-for="item in areaList">{{item.areaName}}</a-menu-item>
            </a-menu>
            <a-button>
              <div class="query-conditions">
                {{ areaName }}
                <a-icon type="down"/>
              </div>
            </a-button>
          </a-dropdown>
        </a-form-item>
        <a-form-item label="停车场" class="marginBtm">
          <a-dropdown class="min-width-200">
            <a-menu slot="overlay" @click="bdParkClick">
              <a-menu-item :key="item.bdParkId" v-for="item in bdParkList">{{item.bdParkName}}</a-menu-item>
            </a-menu>
            <a-button>
              <div class="query-conditions">
                {{ bdParkName }}
                <a-icon type="down"/>
              </div>
            </a-button>
          </a-dropdown>
        </a-form-item>

        <a-form-item label="道口" class="marginBtm">
          <a-dropdown class="min-width-160">
            <a-menu slot="overlay" @click="roadCrossingClick">
              <a-menu-item :key="item.roadCrossingId" v-for="item in roadCrossingList">{{item.roadCrossingName}}</a-menu-item>
            </a-menu>
            <a-button>
              <div class="query-conditions">
                {{ roadCrossingName }}
                <a-icon type="down"/>
              </div>
            </a-button>
          </a-dropdown>
        </a-form-item>

        <a-form-item label="" class="marginBtm">
          <a-checkbox v-model="enableDate">启用日期查询</a-checkbox>
        </a-form-item>
        <a-form-item label="开始" class="marginBtm">
          <a-date-picker
            :allowClear="false"
            :disabled="!enableDate"
            :disabledDate="disabledStartDate"
            format="YYYY-MM-DD"
            v-model="startDate"
            placeholder="开始日期"
            style="width: 150px;margin-right: 1px;"
            @openChange="handleStartOpenChange"
          />
          <a-time-picker v-model="startTime" :disabled="!enableDate" :allowClear="false"/>
        </a-form-item>
        <a-form-item label="结束" class="marginBtm">
          <a-date-picker
            :allowClear="false"
            :disabled="!enableDate"
            :disabledDate="disabledEndDate"
            format="YYYY-MM-DD"
            placeholder="结束日期"
            v-model="endDate"
            :open="endOpen"
            style="width: 150px;margin-right: 1px;"
            @openChange="handleEndOpenChange"
          />
          <a-time-picker v-model="endTime" :disabled="!enableDate" :allowClear="false"/>
        </a-form-item>

        <a-form-item class="marginBtm">
          <a-button type="primary" @click="inquireStart">
            查询
          </a-button>
        </a-form-item>

        <a-form-item class="marginBtm">
          <a-button type="primary" @click="exportList">
            导出
          </a-button>
        </a-form-item>

        <a-form-item class="marginBtm">
          <a-button type="primary" @click="smsNotification">
            批量短信提醒
          </a-button>
        </a-form-item>

        <a-form-item class="marginBtm">
          <a-button type="primary" @click="configuration">
            提醒配置
          </a-button>
        </a-form-item>

      </a-form>
      <!--<a-divider style="margin: 5px 0"/>-->
      <div style="height: 5px"></div>

    </div>

    <a-table
      class="tabled"
      bordered
      :fixed="true"
      size="small"
      :columns="columns"
      :row-key="record => record.xh"
      :data-source="tableData"
      :pagination="pagination"
      :loading="loading"
      :scroll="{ x:xWidth,y: yHeight }"
      :locale="localezh_CN"
      @change="handleTableChange"
      :rowSelection="{selectedRowKeys:selectedRowKeys,onChange:onChange}"
      :customRow="clickRow"
      :rowClassName="setRowClassName"
    >
    </a-table>

    <!--导出加载中-->
    <customLoading :customVisible="spinning" :title="loadingTitle"></customLoading>

    <!--提醒配置-->
    <a-modal
      v-model="modalVisible"
      :destroyOnClose="true"
      :maskClosable="false"
      :keyboard="false"
      title="短信提醒配置"
      @ok="handleOk"
      @cancel="visibleCancel"
      width="500px"
      :confirmLoading="confirmLoading"
    >
      <a-spin :spinning="contentLoading">
        <a-descriptions bordered size="small" :column="3">
          <a-descriptions-item :span="3">
            <template v-slot:label>
              <div class="contShortwidth">第一次短信提醒(天)</div>
            </template>
            <div class="contwidthLon">
              <a-input-number placeholder="请输入第一次短信提醒的时间"
                              v-model="reminderTime.dayOneConfig"
                              :min="0" :precision="0" :formatter="numberRep"
                              :parser="numberRep" style="width: 100%"/>
            </div>
          </a-descriptions-item>
          <a-descriptions-item :span="3">
            <template v-slot:label>
              <div class="contShortwidth">第二次短信提醒(天)</div>
            </template>
            <div class="contwidthLon">
              <a-input-number placeholder="请输入第二次短信提醒的时间"
                              v-model="reminderTime.dayTwoConfig"
                              :min="0" :precision="0" :formatter="numberRep"
                              :parser="numberRep" style="width: 100%"/>
            </div>
          </a-descriptions-item>
        </a-descriptions>
      </a-spin>
      <p style="color: #ff4d4f;margin: 20px 0 0 0">车辆入场时间在第一次和第二次提醒时间之间时发送第一次短信提醒；<br>车辆入场时间超过第二次提醒时间时发送第二次短信提醒。</p>
    </a-modal>

  </div>
</template>

<script>
  import {tableBoxHeight} from "@/api/communal";
  import reservationApi from "@/api/reservation";
  import carPresenceStatisticsApi from "@/api/visitorSystem/carPresenceStatistics";
  import localezh_CN from 'antd/lib/locale-provider/zh_CN';
  import dateUtil from "@/utils/dateUtils";
  import moment from "moment";
  import {ConfigProvider} from 'ant-design-vue';//引用
  import 'moment/locale/zh-cn';
  import cfg from '@/config/config'

  export default {
    components: {
      ConfigProvider
    },
    name: '',
    data() {
      return {
        localezh_CN,
        spinning: false,
        loadingTitle: "正在导出中...",
        delayTime: 500,
        xWidth: "",
        yHeight: "",
        tableData: [],
        pagination: {
          pageSize: 30,
          current: 1,
          total: 0,
          showSizeChanger: true,
          // showQuickJumper: true,
          pageSizeOptions: ["20", "30", "50"],
          showTotal: (total) => `共 ${total} 条`, // 显示总数
          onShowSizeChange: (current, pageSize) => {
            this.pagination.current = 1;
            this.pagination.pageSize = pageSize;
          },
        },
        selectedRow:[],
        selectedRowKeys: [],
        loading: false,
        enableDate: false,
        dateFormat: 'YYYY/MM/DD',
        startDate: "",
        endDate: "",
        endOpen: false,
        startDated: "",
        endDated: "",
        startTime: moment('00:00:00', 'HH:mm:ss'),
        endTime: moment('23:59:59', 'HH:mm:ss'),
        newStartDate: "",	//拼接后的日期时间字符串
        newEndDate: "",		//拼接后的日期时间字符串
        queryValue: "",  //查询值,访客名称，访客手机号
        columns: [],   //表格表头
        statusValue2:"",
        timeTypeName:"小时",
        timeTypeId: 1,
        timeTypeList: [
          {name: "小时", id: 1},
          {name: "天", id: 2},
        ],
        parkingTimeMinute: 0,  //计算后的停车时长分钟数
        statusValue: "不限",
        statusId: 0,
        approvalStatus: [
          {name: "不限", id: 0},
          {name: "24", id: 24},
          {name: "48", id: 48},
          {name: "72", id: 72},
        ],
        //车辆类型
        carTypeName: "全部",
        carTypeId: "",
        carTypeList: [
          {name: "全部", typeId: ""}
        ],
        //基地
        baseName: "全部",
        baseId: "",
        isHaveArea: 0,   //是否有区域 1有 ， 0 没有
        baseList: [
          {name: "全部", id: ""}
        ],
        //区域列表
        areaName: "全部",    //区域名称
        areaId: "",   //99查全部，或者区域id
        areaList: [
          {areaName: "全部", id: ""},
        ],
        //停车场
        bdParkName: "全部",
        bdParkId:"",
        bdParkList:[
          {bdParkName:"全部",bdParkId:""}
        ],
        //出入口、道口
        roadCrossingName: "全部",
        roadCrossingId: 0,
        roadCrossingList: [
          {roadCrossingName: "全部", roadCrossingId: 0}
        ],
        sortedInfo: {
          field: "xh",
          order: "descend"
        },
        form: this.$form.createForm(this, {name: 'passwordFrom'}),
        contentLoading: false,
        confirmLoading: false,
        modalVisible: false,
        reminderTime: {
          dayOneConfig: 1,    //第一次提醒
          dayTwoConfig: 1,    //第二次提醒
          id: 0      //新增0修改传id
        }

      }
    },
    beforeMount() {
      this.columns = [
        {
          title: '序号',     //表头
          dataIndex: 'serialNumber',   //字段名称
          width: '50px',    //设列宽度
          fixed: "left",
          align: 'center',  //居中显示
          className: 'changeBack',   //重置覆盖背景色为浅灰色，否则是白色的
          customRender: (value, row, index) => `${(this.pagination.current - 1) * this.pagination.pageSize + index + 1}`  //设置动态序号
        },
        {
          title: '工号',
          dataIndex: 'userNo',
          key: 'userNo',
          width: '100px',
          align: 'center',
          className: 'changeBack',
          ellipsis: true,
          defaultSortOrder: 'descend',  // 默认倒序
          sortDirections: ['descend', 'ascend'],
          sorter:  (a, b) => {
            if (a.userNo == null || b.userNo == null){
              return -1
            } else {
              return a.userNo.localeCompare(b.userNo, 'en')
            }
          },      // 自定义排序规则
        },
        {
          title: '姓名',
          dataIndex: 'userName',
          key: 'userName',
          width: '100px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack',
          defaultSortOrder: 'descend',  // 默认倒序
          sortDirections: ['descend', 'ascend'],
          sorter: (a, b) => {
            if (a.userName == null || b.userName == null){
              return -1
            } else {
              return a.userName.localeCompare(b.userName, 'en')
            }
          },     // 自定义排序规则
        },
        {
          title: '车牌',
          dataIndex: 'carNo',
          key: 'carNo',
          width: '100px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack',
          defaultSortOrder: 'descend',  // 默认倒序
          sortDirections: ['descend', 'ascend'],
          sorter: (a, b) => {
            if (a.carNo == null || b.carNo == null){
              return -1
            } else {
              return a.carNo.localeCompare(b.carNo, 'en')
            }
          }	,
        },
        {
          title: '车辆类型',
          dataIndex: 'lx',
          width: '120px',
          minWidth: '120px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack',
        },
        {
          title: '入场时间',
          dataIndex: 'inParkTime',
          key: 'inParkTime',
          width: '150px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack',
          defaultSortOrder: 'descend',  // 默认倒序
          sortDirections: ['descend', 'ascend'],
          sorter: (a, b) => {
            if (a.inParkTime == null || b.inParkTime == null){
              return -1
            } else {
              return a.inParkTime.localeCompare(b.inParkTime, 'en')
            }
          }	,     // 自定义排序规则
        },
        {
          title: '停车时长',
          dataIndex: 'inParkTimeDay',
          width: '100px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack',
        },
        {
          title: '已停时间',
          dataIndex: 'inParkTimeMin',
          width: '100px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack'
        },
        {
          title: '基地',
          dataIndex: 'bdStation',
          width: '120px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack'
        },
        {
          title: '区域',
          dataIndex: 'bdAreaName',
          width: '120px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack'
        },
        {
          title: '停车场',
          dataIndex: 'bdParkName',
          width: '190px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack'
        },
        {
          title: '道口',
          dataIndex: 'inParkName',
          width: '140px',
          align: 'center',
          ellipsis: true,
          className: 'changeBack'
        },
        {
          title: '',
          dataIndex: '',
          width: 'auto',
          align: 'center',
          className: 'changeBack'
        }
      ];
      // this.tableData =[
      //   {userNo:12213,userLname:"张四",carName:"F12312",carSbidName:"2131",carInout:"进",visitDateBegin:"",carDatetime:""}
      // ]
      this.startDate = moment().startOf('month');
      this.endDate = moment().endOf('month');
      // this.startDated = moment(this.startDate).format('YYYY-MM-DD HH:mm:ss');
      // this.endDated = moment(this.endDate).format('YYYY-MM-DD HH:mm:ss');
    },
    async mounted() {
      this.xWidth = this.getTableWidth();
      this.statusValue = this.approvalStatus[0].name;
      this.statusId = this.approvalStatus[0].id;
      this.getDtAllcarsqLxs();    // 获取车辆类型
      this.getSmartPositionBdQys();   //获取基地
      await this.inquireStart();
      this.$nextTick(()=>{
        this.yHeight = tableBoxHeight() + 3  + "px";
        let minHeight = document.getElementsByClassName("ant-table");
        minHeight[0].style.minHeight = tableBoxHeight() + 40 + "px";
      });
    },
    methods: {
      // 计算表格宽度
      getTableWidth() {
        let totals = null;
        var el;
        for (el of this.columns) {
          totals += parseInt(el.width);
        }
        return totals + 100 + "px"
      },
      // 选择日期
      onChangePicker(date, dateString) {
        // console.log(date, dateString);
        this.startDated = dateString[0];
        this.endDated = dateString[1];
      },
      //日期控件需要的方法
      disabledStartDate(startDate) {
        const endDate = this.endDate;
        if (!startDate || !endDate) {
          return false;
        }
        return startDate.valueOf() > endDate.valueOf();
      },
      disabledEndDate(endDate) {
        const startDate = this.startDate;
        if (!endDate || !startDate) {
          return false;
        }
        return startDate.valueOf() >= endDate.valueOf();
      },
      handleStartOpenChange(open) {
        // if (!open) {
        //   this.endOpen = true;
        // }
      },
      handleEndOpenChange(open) {
        this.endOpen = open;
      },

      // 导出列表
      async exportList() {
        if(this.enableDate){
          if (!this.verification()) return;
        } else {
          this.newStartDate = "";
          this.newEndDate = "";
        }

        this.spinning = true;
        this.loadingTitle = "正在导出中...";
        let param = {
          current: this.pagination.current,
          pageSize: this.pagination.pageSize,
          startDate: this.newStartDate, //开始时间
          endDate: this.newEndDate,   //结束时间
          parkingTime: this.parkingTimeMinute,
          serchTxt: this.queryValue,
          lx: this.carTypeId,
          bdQy: this.baseId,
          bdAreaId: this.areaId,
          bdParkId: this.bdParkId,
          roadCrossing: this.roadCrossingId,
          sortField: this.sortedInfo.field,   //排序列字段
          sortOrder: this.sortedInfo.order == undefined?'':this.sortedInfo.order=='descend'?'desc':'asc', //排序方式
        };
        let jsonIn = encodeURI(encodeURI(JSON.stringify(param)));
        await window.open(cfg.apiUrl + '/api/parkingLot/exportPresentCarInfoList?jsonIn=' + jsonIn, "_self");
        setTimeout(()=>{
          this.spinning = false;
        },1000)

      },
      async smsNotification(){
        if (this.selectedRow.length == 0){
          this.$message.warning('请选择要短信提醒的人员!');
          return
        }
        this.spinning = true;
        this.loadingTitle = "发送短信中...";
        let res = await carPresenceStatisticsApi.vehicleTimeoutRemindOneOrTwo({
          smsParamList: this.selectedRow
        });
        this.spinning = false;
        // console.log(res);
        if (res.data.success) {
          this.$message.success("发送成功！");
          this.inquireStart();
        } else {
          this.$message.error(res.data.message);
        }
      },

      //验证日期选择（必选日期时验证）
      verification() {
        if (!this.startDate) {
          this.$message.warning('请选择开始日期!');
          return false
        }
        if (!this.endDate) {
          this.$message.warning('请选择结束日期!');
          return false
        }
        let newStartTime = moment(this.startTime).format("HH:mm:ss") == "Invalid date" ? "00:00:00" : moment(this.startTime).format("HH:mm:ss");
        let newEndTime = moment(this.endTime).format("HH:mm:ss") == "Invalid date" ? "23:59:59" : moment(this.endTime).format("HH:mm:ss");
        this.newStartDate = moment(this.startDate).format("YYYY-MM-DD") + " " + newStartTime;
        this.newEndDate = moment(this.endDate).format("YYYY-MM-DD") + " " + newEndTime;
        return true
      },
      calculatingTime(){
        let reg2 = /(^\d+$)/;      //两种都可以
        if (!reg2.test(this.statusId)) {
          this.$message.warning('请输入纯数字的停车时长!');
          return false;
        }

        if (this.statusId == 0){
          this.parkingTimeMinute = 0;
        } else {
          // timeTypeId 1小时 2天
          if (this.timeTypeId == 1){
            this.parkingTimeMinute = this.statusId * 60
          } else if (this.timeTypeId == 2){
            this.parkingTimeMinute = this.statusId * 60 * 24
          }
        }
        return true;
      },
      // 开始查询
      inquireStart() {
        this.selectedRow = [];
        this.selectedRowKeys = [];
        this.pagination.current = 1;
        // this.startDated = this.startDate == "" || this.startDate == null ? "" : moment(this.startDate).format('YYYY-MM-DD HH:mm:ss');
        // this.endDated = this.endDated == "" || this.endDated == null ? "" : moment(this.endDate).format('YYYY-MM-DD HH:mm:ss');
        if (!this.calculatingTime()) return;
        if(this.enableDate){
          if (!this.verification()) return;
        } else {
          this.newStartDate = "";
          this.newEndDate = "";
        }
        let param = {
          current: this.pagination.current, //页码
          pageSize: this.pagination.pageSize, //每页数量
          startDate: this.newStartDate, //开始时间
          endDate: this.newEndDate,   //结束时间
          parkingTime: this.parkingTimeMinute,    //停车时长
          serchTxt: this.queryValue,    //查询关键字
          lx: this.carTypeId,    //车辆类型
          bdQy: this.baseId,    //基地
          bdAreaId: this.areaId,
          bdParkId: this.bdParkId,
          roadCrossing: this.roadCrossingId,    //入口
          sortField: this.sortedInfo.field,   //排序列字段
          sortOrder: this.sortedInfo.order == undefined?'':this.sortedInfo.order=='descend'?'desc':'asc', //排序方式
        };

        this.fetch(param);
      },
      handleMenuSearch(e){
        // console.log(e);
        if (e != ""){
          this.statusValue = e;
          this.statusId = e
        }
      },
      handleMenuChange(e) {
        // console.log(e);
        this.approvalStatus.filter(el => {
          if (el.id == e.key) {
            this.statusValue = el.name;
            this.statusId = el.id
          }
        });
      },

      // 车辆类型
      carTypeClick(e) {
        this.carTypeList.filter(el => {
          if (el.typeId == e.key) {
            this.carTypeName = el.name;
            this.carTypeId = el.typeId
          }
        });
      },
      // 切换基地，选择基地
      baseClick(e) {
        // console.log(e);
        let nowSelect;
        this.baseList.filter(el => {
          if (el.id == e.key) {
            this.baseName = el.name;
            this.baseId = el.id;
            nowSelect = el
          }
        });
        this.areaName = "全部";
        this.areaId = "";
        this.areaList = [{areaName: "全部", id: ""}],
        this.bdParkName = "全部";
        this.bdParkId = "";
        this.bdParkList = [{bdParkName:"全部",bdParkId:""}];
        this.roadCrossingName = "全部";
        this.roadCrossingId = 0;
        this.roadCrossingList = [{roadCrossingName: "全部", roadCrossingId: 0}];
        if (e.key != "") {
          this.getCarParkList(); // 获取停车场
          this.getRoadCrossInfoList();// 获取入口
        }
        if (nowSelect.isHaveArea == 1){
          this.getAreaList()
        }
      },
      // 切换区域，选择区域
      areaMenuClick(e) {
        // console.log(e);
        this.areaList.filter(el => {
          if (el.id == e.key) {
            // console.log(el);
            this.areaName = el.areaName;
            this.areaId = el.id;

            this.bdParkName = "全部";
            this.bdParkId = "";
            this.bdParkList = [{bdParkName:"全部",bdParkId:""}];
            this.roadCrossingName = "全部";
            this.roadCrossingId = 0;
            this.roadCrossingList = [{roadCrossingName: "全部", roadCrossingId: 0}];
          }
        });
        if (e.key != "" || this.baseId != ""){
          this.getCarParkList(); // 获取停车场
          this.getRoadCrossInfoList();// 获取入口
        }
      },
      bdParkClick(e) {
        // console.log(e);
        this.bdParkList.filter(el => {
          if (el.bdParkId == e.key) {
            this.bdParkName = el.bdParkName;
            this.bdParkId = el.bdParkId;
          }
        });
        this.roadCrossingName = "全部";
        this.roadCrossingId = 0;
        this.roadCrossingList = [{roadCrossingName: "全部", roadCrossingId: 0}];
        if (e.key != "" || this.baseId != "") {
          this.getRoadCrossInfoList(); // 获取入口
        }
      },
      // 切换入口
      roadCrossingClick(e) {
        this.roadCrossingList.filter(el => {
          if (el.roadCrossingId == e.key) {
            this.roadCrossingName = el.roadCrossingName;
            this.roadCrossingId = el.roadCrossingId
          }
        });
      },

      // 点击行
      clickRow(record) {
        return {
          on: {
            click: () => {
              if (this.selectedRowKeys.indexOf(record.xh) > -1) {
                this.selectedRow = this.selectedRow.filter(v => {
                  return v.xh != record.xh
                })
                this.selectedRowKeys.splice(this.selectedRowKeys.indexOf(record.xh), 1)
              } else {
                this.selectedRow.push(record)
                this.selectedRowKeys.push(record.xh)
              }
            }
          }
        }

      },
      setRowClassName(record){
        return this.selectedRowKeys.indexOf(record.xh) > -1 ? 'clickRowStyl' : '';
      },

      // 表格切换分页
      handleTableChange(pagination, filters, sorter) {
        console.log(sorter);
        console.log(sorter.order);
        this.sortedInfo = sorter;
        // this.startDated = this.startDate == "" || this.startDate == null ? "" : moment(this.startDate).format('YYYY-MM-DD HH:mm:ss');
        // this.endDated = this.endDated == "" || this.endDated == null ? "" : moment(this.endDate).format('YYYY-MM-DD HH:mm:ss');
        if(this.enableDate){
          if (!this.verification()) return;
        } else {
          this.newStartDate = "";
          this.newEndDate = "";
        }
        const pager = {...this.pagination};
        pager.current = pagination.current;
        this.pagination = pager;
        this.fetch({
          pageSize: pagination.pageSize,
          current: pagination.current,
          startDate: this.newStartDate, //开始时间
          endDate: this.newEndDate,   //结束时间
          parkingTime: this.parkingTimeMinute,
          serchTxt: this.queryValue,
          lx: this.carTypeId,
          bdQy: this.baseId,
          bdAreaId: this.areaId,
          bdParkId: this.bdParkId,
          roadCrossing: this.roadCrossingId,
          sortField: this.sortedInfo.field,   //排序列字段
          sortOrder: this.sortedInfo.order == undefined?'':this.sortedInfo.order=='descend'?'desc':'asc', //排序方式 正序asc 倒序desc
          ...filters,
        });
      },
      onChange(selectedRowKeys, selectedRows) {
        // console.log(selectedRowKeys, selectedRows);
        this.selectedRowKeys = selectedRowKeys;
        this.selectedRow = selectedRows;
      },
      // 请求表格数据--测试用
      async fetch(params) {
        this.loading = true;
        let resp = await carPresenceStatisticsApi.getPresentCarInfoList(params);
        // console.log(resp.data);
        if (resp.data.success) {
          this.loading = false;
          this.pagination.total = resp.data.result.total;
          this.tableData = resp.data.result.records;

        } else {
          this.loading = false;
          this.$message.error(resp.data.message);
        }

      },

      // 车辆类型
      async getDtAllcarsqLxs() {
        let res = await reservationApi.getDtAllcarsqLxs()
        if (res.data.success) {
          this.carTypeList = [...this.carTypeList, ...res.data.result];
        } else {
          this.$message.error(res.data.message);
        }
      },

      // 获取基地
      async getSmartPositionBdQys() {
        let res = await reservationApi.getBdSysItemList({typeId: 200});
        // console.log(res);
        if (res.data.success) {
          this.baseList = [...this.baseList, ...res.data.result];
        } else {
          this.$message.error(res.data.message);
        }
      },
      // 获取区域
      async getAreaList() {
        let res = await reservationApi.getBdVisitAreaListByRoleNew({typeId: this.baseId})
        // console.log(res.data);
        if (res.data.success) {
          this.areaList = [{areaName: "全部", id: ""}];
          this.areaList = [...this.areaList, ...res.data.result];
        } else {
          this.$message.error(res.data.message);
        }
      },
      // 根据基地获取入口、道口
      async getRoadCrossInfoList() {
        let res = await carPresenceStatisticsApi.getRoadCrossInfoList({
          fx: 1,
          bdStation: this.baseId,
          bdAreaId: this.areaId,
          bdParkId: this.bdParkId   //停车场id
        });
        // console.log(res);
        if (res.data.success) {
          if (res.data.success) {
            this.roadCrossingList = [{roadCrossingName: "全部", roadCrossingId: 0}];
            if (res.data.result && res.data.result.length > 0) {
              res.data.result.forEach(el => {
                this.roadCrossingList.push({
                  roadCrossingName: el.parkName,
                  roadCrossingId: el.parkSerial
                })
              })
            }
          }
          // this.roadCrossingList = [...this.roadCrossingList, ...res.data.result];
        } else {
          this.$message.error(res.data.message);
        }
      },
      async configuration(){
        this.contentLoading = true;
        this.modalVisible = true;
        let res = await carPresenceStatisticsApi.getOneAndTwoConfigInfo();
        // console.log(res);
        if (res.data.success) {
          this.contentLoading = false;
          if (res.data.result && res.data.result.length > 0){
            this.reminderTime = res.data.result[0]
          }
        } else {
          this.contentLoading = false;
          this.$message.error(res.data.message);
        }
      },
     async handleOk(e) {
          this.contentLoading = true;
          this.confirmLoading = true;
          let res = await carPresenceStatisticsApi.configOneAndTwoInfo(this.reminderTime);
          this.contentLoading = false;
          this.confirmLoading = false;
          if (res.data.success) {
            this.$message.success("配置成功！");
            this.visibleCancel();
          } else {
            this.$message.error(res.data.message);
          }
      },
      //取消、关闭弹窗
      visibleCancel() {
        this.contentLoading = false;
        this.modalVisible = false;
        this.reminderTime.dayOneConfig = 1;
        this.reminderTime.dayTwoConfig = 1;
        this.reminderTime.id = 0;
      },
      //只能输入整数,有字母或汉字返回空
      numberRep(value){
        if (typeof value === 'string') {
          return !isNaN(Number(value)) ? value.replace(/^(0+)|[^\d]/g, '') : ''
        } else if (typeof value === 'number') {
          return !isNaN(value) ? String(value).replace(/^(0+)|[^\d]/g, '') : ''
        } else {
          return ''
        }
      },
      // 根据基地获取停车场
      async getCarParkList() {
        let res = await reservationApi.getCarParkDate({
          bdStation: this.baseId,
          bdAreaId: this.areaId
        });
        console.log(res.data);
        if (res.data.success) {
          this.bdParkList = [{bdParkName:"全部",bdParkId:""}];
          this.bdParkList = [...this.bdParkList, ...res.data.result];
        } else {
          this.$message.error(res.data.message);
        }
      },
      columnlocaleCompare: (a,b)=> {
        console.log("打印a，b");
        console.log(a,b);
        a.userNo.localeCompare(b.userNo, 'en');
      },

    },
  }
</script>

<style scoped>

</style>

